package com.demo.controller;

import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller
public class UserController {

//    //属性注入
//    @Autowired  //注入对象（更加简单的从spring容器中读取对象
//    private UserService userService;

//    //setter注入
//    private UserService userService;
//
//    @Autowired
//    public void setUserService(UserService userService) {
//        this.userService = userService;
//    }


    //3.构造方法注入
    private UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    public void sayHi(){
        System.out.println("com.demo->do UserContoller sayHi()");
        userService.sayHi();
    }
}
